package com.wuwei.elearning.question.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wuwei.elearning.question.domain.Subject;
import com.wuwei.elearning.question.mapper.SubjectMapper;
import com.wuwei.elearning.question.service.SubjectService;
import com.wuwei.elearning.utils.result.Result;
import com.wuwei.elearning.vo.SubjectVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wuwei
 * @since 2024-02-01
 */
@RestController
@RequestMapping("/elearning/subject")
@CrossOrigin
public class SubjectController {

    @Resource
    private SubjectMapper subjectMapper;

    @Resource
    private SubjectService subjectService;

    /**
     * 获取所有R3基础执照考试科目
     * @return
     */
    @GetMapping("getAllR3")
    public Result<List<Subject>> getAll (){
        LambdaQueryWrapper<Subject> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(Subject::getName,"R3");
        List<Subject> subjects = subjectMapper.selectList(wrapper);
        return Result.ok(subjects);
    }

    /**
     * 获取满足vant要求的数据结构
     *    options: [
     *         {
     *           text: '浙江省',
     *           value: '330000',
     *           children: [{ text: '杭州市', value: '330100' }],
     *         },
     *         {
     *           text: '江苏省',
     *           value: '320000',
     *           children: [{ text: '南京市', value: '320100' }],
     *         },
     *       ],
     *
     * @return
     */
    @GetMapping("getTree")
    public Result<List<SubjectVo>> getTree (){
        List<SubjectVo> vos = subjectService.getTree();
        return Result.ok(vos);
    }


}

